package GUI;

import java.awt.Rectangle;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import Client_logic.ClientNotInitializesException;
import Client_logic.ConnectionToServer;

/**
 * This is a abstract class to all main panels for clients use for logOF button
 * @author michael
 * @author ido
 * @author sharon
 * @author matan
 */
public abstract class ClientAbstractFORM extends JPanel
{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 3434830013656310168L;
	private JButton logOffButton = null;
	
	/**
	 * This is the default constructor
	 */
	public ClientAbstractFORM() 
	{
		super();
		initialize();	
	}
	
	/**
	 * This method initializes ClientAbstractFORM
	 */
	private void initialize() 
	{
		this.setSize(500, 500);
		this.setLayout(null);
		this.add(getActiveCampaignButton());
	}
	
	/**
	 * This method initializes logOffButton	
	 */
	private JButton getActiveCampaignButton() 
	{
		if (logOffButton == null) 
		{
			logOffButton = new JButton();
			logOffButton.setBounds(new Rectangle(300, 10, 70, 21));
			logOffButton.setText("LogOF");
			logOffButton.addActionListener(new java.awt.event.ActionListener() 
			{
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{			
					try
					{
						ConnectionToServer connectiontoserver = new ConnectionToServer();
						String loggedofmsg = (String)connectiontoserver.logOf();
						if(loggedofmsg != null && loggedofmsg.equals("LoggedOF"))
						{
							JOptionPane.showMessageDialog(null, "Lgged of successfuly");
							System.exit(0);
						}
						else
							JOptionPane.showMessageDialog(null, "ERROR!!!","",JOptionPane.WARNING_MESSAGE);
					} catch (ClientNotInitializesException e1) 
					{
						System.exit(0);
					}					
				}
			});
		}
		return logOffButton;
	}
}
